package com.zch.starter.opentelemetry.agent.mode.springboot.starter.interceptor;

import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Spring的InterceptorRegistry会合并所有WebMvcConfigurer的拦截器配置。
 * 不用担心会影响业务层自定义的拦截器
 */
public class TraceInterceptorConfiguration implements WebMvcConfigurer {
    private  TraceIdInterceptor traceIdInterceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(traceIdInterceptor)
                .addPathPatterns("/**")//拦截所有接口
                .order(Integer.MIN_VALUE);//设置优先级最高
    }

    public TraceInterceptorConfiguration(TraceIdInterceptor traceIdInterceptor) {
        this.traceIdInterceptor = traceIdInterceptor;
    }
}
